﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HttpRequester;
using System.Net;
using BotvaBot.Configuration.Personaj;

namespace BotvaBot.RequestChains.Base
{
    public class BotvaChainBase : RequestChain<BotvaChainContext>
    {
        public PersonajCfg Personaj { get; set; }
        //public string Name { get; set; }
        //public string Password { get; set; }

        public override BotvaChainContext Context
        {
            get
            {
                base.Context.Personaj = Personaj;
                return base.Context;
            }
            set { base.Context = value; }
        }


        //public ovee BotvaChainContext BotvaContext 
        //{
        //    get
        //    {
        //        BotvaChainContext botvaContext = Context as BotvaChainContext;
        //        if (botvaContext != null)
        //        {
        //            botvaContext.Name = Name;
        //            botvaContext.Password = Password;
        //        }
        //        return botvaContext;
        //    }
        //}


        public BotvaChainBase()
            : base()
        { }

        public BotvaChainBase(BotvaChainContext parentContext)
            : base(parentContext)
        { }


        public override void Init()
        {
            base.Init();

            Context = new BotvaChainContext(ParentContext as BotvaChainContext);

            AddWellknownHeaders(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729; .NET4.0E)");
            AddWellknownHeaders(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            AddWellknownHeaders(HttpRequestHeader.Connection, "Keep-Alive");
            AddWellknownHeaders(HttpRequestHeader.AcceptLanguage, "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3");
            AddWellknownHeaders(HttpRequestHeader.AcceptCharset, "windows-1251,utf-8;q=0.7,*;q=0.7");

            AddCustomHeader("Keep-Alive", "115");
        }

        //public override void CopyContext(RequestChainContext parentContext)
        //{
        //    base.CopyContext(parentContext);

        //    if (parentContext is BotvaChainContext)
        //    {
        //        BotvaChainContext parentBotvaContext = parentContext as BotvaChainContext;
        //        Name = parentBotvaContext.Name;
        //        Password = parentBotvaContext.Password;
        //    }
        //}
    }
}
